package StudyCode.summary.zipfile;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;

/**
 * 版权所有 科技与人文(www.tah1986.com)
 */
public class ExtractFirstFileFromZipFile {
	public static void main(String args[]) {

		String sourceZipFile = "E:/Copy/zipdemo.zip";

		try {
			FileInputStream fin = new FileInputStream(sourceZipFile);

			ZipInputStream zin = new ZipInputStream(fin);

			ZipEntry entry = zin.getNextEntry();

			OutputStream os = new FileOutputStream("E:/Copy/1.csv");

			byte[] buffer = new byte[1024];
			int length;

			while ((length = zin.read(buffer)) > 0) {
				os.write(buffer, 0, length);
			}
			os.close();

			zin.close();

			System.out.println("从zip文件中提取的文件成功");
		} catch (IOException e) {
			e.printStackTrace();
		}

	}
}
